package com.credithc.signature.common.ro.manager;

import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import org.apache.commons.lang.StringUtils;
import org.springframework.format.annotation.DateTimeFormat;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * 描述：<br/>
 * 作者：sunyang
 * 创建：2019/6/19 9:51
 * 版本：v1.0.0<br/>
 */
@Data
public class SignLogRo {
    private String requestSN;
    private String templateNo;
    private String templateName;
    /**
     * 0:全部
     * 1:私章
     * 2:公章
     * 3:公私章
     */
    private Integer signType;

    /**
     * 0 全部
     * 1 未签章
     * 2 签章中
     * 3 签章成功
     * 4 签章失败
     */
    private Integer signStatus;
    private Integer needSign;
    private String tenantName;
    private String channelName;
    private String channelAdmin;
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8", locale = "zh")
    private Date startTime;
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8", locale = "zh")
    private Date endTime;

    private Integer callbackSts;

    private String timeRange;

    private Integer companyId;

    private String code;

    private Integer userId;

    private Integer pageNo;
    private Integer pageSize;

    List<String> channelIds;

    public static final String REQUEST_SN = "request_sn";
    public static final String TEMPLATE_NO = "template_no";
    public static final String SIGN_STATUS = "sign_status";
    public static final String IS_SEAL = "is_seal";
    public static final String CHANNEL_NO = "channel_no";
    public static final String CREATE_TIME = "create_time";

    public Integer getSignType() {
        if (signType == null || signType == 0) {
            return null;
        }
        return signType;
    }

    public Integer getNeedSign(){
        if (needSign == null){
            return null;
        }
        if (needSign == 1) {
            return 1;
        } else if (needSign == 2) {
            return 0;
        }
        return null;
    }
    public void setTimeRange(String timeRange) {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        this.timeRange = timeRange;
        if (StringUtils.isNotBlank(timeRange)){
            try {
                String[] split = timeRange.split(" - ");
                this.startTime = simpleDateFormat.parse(split[0]);
                this.endTime = simpleDateFormat.parse(split[1]);
            } catch (ParseException e) {
                e.printStackTrace();
            }
        }
    }


}
